package com.ibl.rover.lite.common.bean;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

public class SettingBean extends BaseBean {

	@ColumnOrder(Order = 1)
	private String serverUrl;
	@ColumnOrder(Order = 2)
	private String serverPort;

	public static final String COL_SERVER_URL = "SERVER_URL";
	public static final String COL_SERVER_PORT = "SERVER_PORT";

	public static final int IDX_COL_SERVER_URL = 1;
	public static final int IDX_COL_SERVER_PORT = 2;

	private static AutomatedQueryStatement AUTO_GEN_QUERY;

	static {
		AUTO_GEN_QUERY = SQLiteDatabaseHelper
				.getAutoGeneratedStmts(SettingBean.class);
	}

	@Override
	public void bind(SQLiteStatement sqlLiteStatement) {
		sqlLiteStatement.bindString(IDX_COL_SERVER_URL, getServerUrl());
		sqlLiteStatement.bindString(IDX_COL_SERVER_PORT, getServerPort());

	}

	@Override
	public <T extends BaseBean> T cursorBind(Cursor cursor) {
		SettingBean settingBean = new SettingBean();
		settingBean.set_id(cursor.getInt(IDX_COL_ID));
		settingBean.setServerUrl(cursor.getString(IDX_COL_SERVER_URL));
		settingBean.setServerPort(cursor.getString(IDX_COL_SERVER_PORT));
		return (T) settingBean;
	}

	@Override
	public <T extends BaseBean> T cursorInit(Cursor cursor) {
		this.set_id(cursor.getInt(IDX_COL_ID));
		this.setServerUrl(cursor.getString(IDX_COL_SERVER_URL));
		this.setServerPort(cursor.getString(IDX_COL_SERVER_PORT));
		return (T) this;
	}

	@Override
	public ContentValues bindContentValues() {
		ContentValues contentValues = new ContentValues();
		contentValues.put(COL_SERVER_PORT, serverPort);
		contentValues.put(COL_SERVER_URL, serverUrl);
		return contentValues;
	}

	@Override
	public String getCreateTableQuery() {

		return AUTO_GEN_QUERY.getCreateTableQuery();
	}

	@Override
	public String getInsertQuery() {

		return AUTO_GEN_QUERY.getPreparedInsertQuery();
	}

	@Override
	public String getDeleteQuery() {

		return AUTO_GEN_QUERY.getPreparedDeleteQuery();
	}

	@Override
	public String getUpdateQuery() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getTableName() {

		return AUTO_GEN_QUERY.getTableName();
	}

	public String getServerUrl() {
		return serverUrl;
	}

	public void setServerUrl(String serverUrl) {
		this.serverUrl = serverUrl;
	}

	public String getServerPort() {
		return serverPort;
	}

	public void setServerPort(String serverPort) {
		this.serverPort = serverPort;
	}

}
